#ifndef GET_DT35_H_
#define GET_DT35_H_

#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <limits.h>
#include <string.h>
#include <string>
#include <queue>
#include <thread>

const long long Bufflen = 1024;

typedef enum{
    _115200,
    _9600
}E_BaudRate;

typedef enum{
    _7,
    _8
}E_DataSize;

typedef enum
{
    None,
    Odd,
    Even,
}E_Parity;

typedef enum
{
    _1,
    _2,
}E_StopBit;

class Serial{

public:
    Serial();
    ~Serial();

    void SetSimulationMode(bool isSimulation);

    int OpenSerial(std::string SerialID,E_BaudRate Bps, E_DataSize DataSize, E_Parity Parity, E_StopBit StopBit);
    int Recv(unsigned char *Buff, int length);
    void Send_from(const std::vector<uint8_t>& data);
    void Send_to(const std::vector<uint8_t>& data);

    int Close();

private:
    void RunRecv();
    int RefreshBuffer(unsigned char *pBuf, int Len, bool RecvTypet);

    int nSerialID;
    bool b_OpenSign;
    struct termios ProtoOpt;

    bool b_SimulationMode;
    std::queue<unsigned char> simulationQueue;
    std::thread ThRecv;
};

#endif